package com.eati.cm.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;

public class CastUtil {
    static public String toJson(Object obj) throws JsonProcessingException {
    	ObjectMapper om = new ObjectMapper();
    	om.registerModule(new Hibernate5Module());
        return om.writeValueAsString(
                obj
        );
    }
    static public String toJsonNoExcp(Object obj) {
     	ObjectMapper om = new ObjectMapper();
    	om.registerModule(new Hibernate5Module());
        try {
			return om.writeValueAsString(
			        obj
			);
		} catch (JsonProcessingException e) {
			return "To json err. excp: " + e.toString();
		}
    }
}
